namespace CLELCore.Assembly.MethodHeaderDataSections.MethodHeaderDataSectionRows
{
	public class SEHDataSectionRow : MethodHeaderDataSectionRow
	{
		private bool _sect_fat;
		private int _flags;
		private int _tryoffset;
		private int _trylength;
		private int _handleroffset;
		private int _handlerlength;
		private int _tokenoroffset;

		public int Flags
		{
			get
			{
				return _flags;
			}
			set
			{
				_flags = value;
			}
		}
		public int TryOffset
		{
			get
			{
				return _tryoffset;
			}
			set
			{
				_tryoffset = value;
			}
		}
		public int TryLength
		{
			get
			{
				return _trylength;
			}
			set
			{
				_trylength = value;
			}
		}
		public int HandlerOffset
		{
			get
			{
				return _handleroffset;
			}
			set
			{
				_handleroffset = value;
			}
		}
		public int HandlerLength
		{
			get
			{
				return _handlerlength;
			}
			set
			{
				_handlerlength = value;
			}
		}
		public int TokenOrOffset
		{
			get
			{
				return _tokenoroffset;
			}
			set
			{
				_tokenoroffset = value;
			}
		}

		public int Size
		{
			get
			{
				if(_sect_fat)
					return MethodHeaderDataSection.FAT_DATA_ROW_SIZE;
				return MethodHeaderDataSection.TINY_DATA_ROW_SIZE;
			}
		}

		public bool IsFat
		{
			get
			{
				return _sect_fat;
			}
		}

		public byte[] GetBytes(bool little_endian)
		{
			byte[] ret;

			if(_sect_fat)
			{
				ret = new byte[MethodHeaderDataSection.FAT_DATA_ROW_SIZE];
				Bits.SetInt(0,ret,_flags,little_endian);
				Bits.SetInt(4,ret,_tryoffset,little_endian);
				Bits.SetInt(8,ret,_trylength,little_endian);
				Bits.SetInt(12,ret,_handleroffset,little_endian);
				Bits.SetInt(16,ret,_handlerlength,little_endian);
				Bits.SetInt(20,ret,_tokenoroffset,little_endian);
			}
			else
			{
				ret = new byte[MethodHeaderDataSection.TINY_DATA_ROW_SIZE];
				Bits.SetShort(0,ret,(short)_flags,little_endian);
				Bits.SetShort(2,ret,(short)_tryoffset,little_endian);
				ret[4] = (byte)_trylength;
				Bits.SetShort(5,ret,(short)_handleroffset,little_endian);
				ret[7] = (byte)_handlerlength;
				Bits.SetInt(8,ret,_tokenoroffset,little_endian);
			}

			return ret;
		}

		public SEHDataSectionRow(int flags,int tryoffset,int trylength,
			int handleroffset,int handlerlength,int tokenoroffset,bool sect_fat)
		{
			_flags = flags;
			_tryoffset = tryoffset;
			_trylength = trylength;
			_handleroffset = handleroffset;
			_handlerlength = handlerlength;
			_tokenoroffset = tokenoroffset;
			_sect_fat = sect_fat;
		}
	}
}
